<?php

class foundation_Model_DbTable_DbSubject extends Zend_Db_Table_Abstract
{

    protected $_name = 'tbl_subject';
	//function for getting record user by user_id
    public function selectsubject(){
    	$db = new Application_Model_DbTable_DbGlobal();
    	//$db = $this->getAdapter();
    	$sql = "SELECT *,
    			(SELECT fac_name From tbl_faculty as f Where f.fac_id = s.fac_id ) as fac_id,
    			(SELECT dpt_name From tbl_departments as d Where d.dpt_id = s.dpt_id) as dpt_id,
    			(SELECT year_name From tbl_year as y Where y.year_id = s.year_id) as year_ids,
    			(SELECT semester_name From tbl_semester as se Where se.semester_id = s.semester_id) as semester_ids
    			 FROM tbl_subject as s Where s.year_id = 1";
    	return  $db->getGlobalDb($sql);
    }
    public function getsubject($id){
    	$db = $this->getAdapter();
    	$sql = "Select * From tbl_subject where subject_id =".$id." LIMIT 1";
    	$rows = $db->fetchRow($sql);
		return $rows;
    }
	public function insertsubject($arr)
	{ 
		//print_r($arr);exit();
     	$array_data = array(
     			"fac_id"	=>	$arr["fac_id"],
     			"dpt_id"	=>	$arr["dpt_id"],
     			"year_id"	=>	$arr["year_id"],
     			"semester_id"	=>	$arr["semester_id"],
     			"subject_name"	=>	$arr["subject_name"],
     			"ordering"	=>	$arr["ordering"],
     			"description" =>$arr["description"],
     			"status"	=>	1,
     			"created_date"	=>	date("Y-m-d H:i:s")
     			);
     	$id=$this->insert($array_data);
     	

	}
	public function updateStatus($arr)
	{
		$array_data = array(
				"subject_id"	=>	$arr["subject_id"],
				"status"	=>	1
		);
		$where = $this->getAdapter()->quoteInto('subject_id=?', $arr["subject_id"]);
		//echo $where; exit();
		$this->update($array_data, $where);
			
	}
	public function updateUnStatus($arr)
	{
		$array_data = array(
				"subject_id"	=>	$arr["subject_id"],
				"status"	=>	0
		);
		$where = $this->getAdapter()->quoteInto('subject_id=?', $arr["subject_id"]);
		//echo $where; exit();
		$this->update($array_data, $where);
			
	}
	public function updatsubject($arr)
	{
			$array_data = array(
     			"fac_id"	=>	$arr["fac_id"],
     			"dpt_id"	=>	$arr["dpt_id"],
     			"year_id"	=>	$arr["year_id"],
     			"semester_id"	=>	$arr["semester_id"],
     			"subject_name"	=>	$arr["subject_name"],
     			"ordering"	=>	$arr["ordering"],
     			"description" =>$arr["description"],
     			"status"	=>	1,
     			"created_date"	=>	date("Y-m-d H:i:s")
     			);
			$where = $this->getAdapter()->quoteInto('subject_id=?', $arr["subject_id"]);
			$this->update($array_data, $where);
			//print_r($where); exit();
	}
	public function deletesubject($id){
		$db = $this->getAdapter();
		$sql = "Delete From tbl_subject Where subject_id=".$id;
		$row = $db->query($sql);
		return $row;
	}

}

